let db=require('../db/index')

exports.registerAPI=(req,res)=>{
    // var sql='select * from user'
    // ${req.username}
    // ${req.body.username}/*  */
    console.log(req)
    var sql1=`select * from user where username ='${req.query.username}'`
    // console.log(sql1)
    var sql = `insert into user(username,password) value('${req.query.username}','${req.query.password}')`
    // console.log('req.username'+req.username)
    // var sql = `update user set user = '${req.body.user}'
     db.query(sql1,[
        req.query.username,
        req.query.password,
        req.query.sex,
        req.query.email,      
    ],(err,data)=>{
        if(err){
            return res.send('错误:'+err.message+'找不到该用户')
        }
        if(data.length!=0 &&req.query.username === data[0].username){
            // console.log('此用户名已经被注册，请你重新注册')
            // res.status(404).send({'msg':'用户名已被注册'}) 
            // 这里提示一下前端，用户名已经被注册     功能还没写完
        }
        return
    })

    db.query(sql,[
        req.query.username,
        req.query.password,
        req.query.sex,
        req.query.email,
        
        
    ],(err,data)=>{
        if(err){
            return res.send('错误:'+err.message+'找不到该用户')
        }
        res.send(data)
    })
}